<?php
namespace app\common\library\xilujob\resume;

use app\common\library\xilujob\ResumeLibrary;
use app\common\model\xilujob\Resume;
use app\common\model\xilujob\ResumeWork;
use think\Model;

class Work extends BaseModule {

    protected $name = ResumeLibrary::MODULE_WORK;

    public function onCreateResume(Resume $resume) {}

    /**
     * 获取所有字段的key
     * @return array
     */
    protected function keys() {
        return ['job_title','company_name', 'start', 'end', 'detail'];
    }

    /**
     * 获取验证规则
     * @return array
     */
    protected function getRules() {
        return [
            'job_title' => 'require|length:1,20',
            'company_name' => 'require|length:1,50',
            'start' => 'require|dateFormat:Y-m',
            'end' => ['require','regex'=>'/^(\d{4}-((0([1-9]))|(1(0|1|2))))|(至今)$/','>:start'],
            'detail' => 'require|length:1,500'
        ];
    }

    /**
     * 获得Model实例
     * @return Model
     */
    protected function getModel() {
        return new ResumeWork();
    }

    /**
     * @return array score: 当前分数， max: 满分
     */
    public function getCompleteScore() {
        $max = 20;
        $count = ResumeWork::where('resume_id',$this->resume->id)->count();
        $score = $count>0 ? 20 : 0;
        return ['score'=>$score, 'max'=>$max];
    }

}